export const createSetAction = (payload) => ({
  type: 'set',
  payload
})

export const createAddAction = (payload) => {
  return (dispatch, getState) => {
    setTimeout(() => {
      const {
        todos
      } = getState()
      if (!todos.find(todo => todo.text === payload)) {
        dispatch({
          type: 'add',
          payload: {
            text: payload,
            id: Date.now(),
            complete: false,
          }
        })
      }
    }, 3000)
  }
}

export const createRemoveAction = (payload) => ({
  type: 'remove',
  payload
})

export const createToggleAction = (payload) => ({
  type: 'toggle',
  payload
})